package com.finer.service.impl;

import com.finer.entity.finance.FinerStocktaking;
import com.finer.dao.FinerStocktakingDao;
import com.finer.service.FinerStocktakingService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 盘点记录表(FinerStocktaking)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:41
 */
@Service("finerStocktakingService")
public class FinerStocktakingServiceImpl implements FinerStocktakingService {
    @Resource
    private FinerStocktakingDao finerStocktakingDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerStocktaking queryById(Integer id) {
        return this.finerStocktakingDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerStocktaking 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerStocktaking> queryByPage(FinerStocktaking finerStocktaking, PageRequest pageRequest) {
        long total = this.finerStocktakingDao.count(finerStocktaking);
        return new PageImpl<>(this.finerStocktakingDao.queryAllByLimit(finerStocktaking, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerStocktaking 实例对象
     * @return 实例对象
     */
    @Override
    public FinerStocktaking insert(FinerStocktaking finerStocktaking) {
        this.finerStocktakingDao.insert(finerStocktaking);
        return finerStocktaking;
    }

    /**
     * 修改数据
     *
     * @param finerStocktaking 实例对象
     * @return 实例对象
     */
    @Override
    public FinerStocktaking update(FinerStocktaking finerStocktaking) {
        this.finerStocktakingDao.update(finerStocktaking);
        return this.queryById(finerStocktaking.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerStocktakingDao.deleteById(id) > 0;
    }
}
